package com.yiduan.apollocrm.views.mediators
{
	
	import com.yiduan.apollocrm.models.Product;
	import com.yiduan.apollocrm.views.NewOrEditProductView;
	
	import org.robotlegs.mvcs.Mediator;
	
	public class NewOrEditProductMediator extends Mediator
	{
		[Inject]
		public var newOrEditProductView:NewOrEditProductView;
		
		public function NewOrEditProductMediator() {
			super();
		}
		
		override public function onRegister():void {
			updateViewData();
		}
		
		private function updateViewData():void {
			if (newOrEditProductView.data == null) {
				newOrEditProductView.currentState = "new";
			} else {
				newOrEditProductView.currentState = "edit";
				var product:Product = newOrEditProductView.data as Product;
				newOrEditProductView.nameInput.text = product.name;
				newOrEditProductView.codeInput.text = product.code;
				newOrEditProductView.descriptionInput.text = product.description;
			}
		}
	}
}